package org.langqiao.jvm.base;

import java.util.ArrayList;
import java.util.List;

class OOMObject {

	static class OOMObject1{
		public byte[] placeholder = new byte[64*1024];
	}
	
	public static void fillheap(int num){
		List<OOMObject1> list = new ArrayList<OOMObject1>();
		for(int i=0;i<num;i++){
			list.add(new OOMObject1());
		}
		
	}
	
	static class SynAddRunnable implements Runnable{
		int a,b;
		public SynAddRunnable(int a, int b){
			this.a = a;
			this.b = b;
		}
		
		@Override
		public void run() {
			synchronized (Integer.valueOf(a)) {
				synchronized (Integer.valueOf(b)) {
					System.out.println(a + b);
				}
				
			}
		}
	}
	
	public static void main(String[] args) {
		//fillheap(1000);
		//System.gc();
		for(int i=0;i<1000;i++){
			new Thread(new SynAddRunnable(1, 2)).start();
			new Thread(new SynAddRunnable(2, 1)).start();
		}
	}
}
